﻿/**
*TextMarquee class
*auth:lww
*version:1.0
*date:2014-10-11
*/
function TextMarquee() {
    this.version = "1.0.0";
    this.name = "TextMarquee";
    this.timer = null;
    this.timer_ticks = 33;
    this.timer_wait = 0;
    this.e = null;
    this.src_txt = "";
    this.txtFontSize = 0;
    this.txtWidth = 0;
    this.spaceStr = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
    this.spaceCharCount = 8;
    this.spaceWidth = 128;
}
TextMarquee.prototype.Marquee = function () {
    if (this.e != null) {
        if (this.timer_wait > 0) {
            var t = (new Date).getTime();
            if (t - this.timer_wait > 3000) {
                this.timer_wait = 0;
                this.e.scrollLeft = 0;
            }
            return;
        }

        if (this.e.scrollLeft >= (this.txtWidth / 2 - this.e.scrollWidth / 2)) {
            this.timer_wait = (new Date).getTime();
            return;
        }
        if (this.e.scrollLeft + this.e.scrollWidth < this.txtWidth) {
            this.e.scrollLeft++;
        }
    }
};
TextMarquee.prototype.Star = function (o) {
    this.Stop();
    if (o == null)
        return;
    this.e = o;
    this.e.scrollLeft = 0;
    this.src_txt = this.e.innerText;
    this.txtFontSize = parseInt(getComputedStyle(this.e, null).fontSize, 10);
    this.txtWidth = getStrLenWithGB(this.e.innerText) * this.txtFontSize;
    if (this.e.scrollWidth == 0 || this.txtWidth <= this.e.scrollWidth)
        return;
    /*set Marquee args*/
    this.spaceWidth = this.spaceCharCount * this.txtFontSize;
    this.e.innerHTML = this.src_txt + this.spaceStr + this.src_txt;
    this.txtWidth = getStrLenWithGB(this.e.innerText) * this.txtFontSize;
    /**start marquee**/
    var z = this;
    z.timer = setInterval(function () { z.Marquee(); }, z.timer_ticks);
};
TextMarquee.prototype.Stop = function () {
    if (this.timer != null) {
        clearInterval(this.timer);
        this.timer = null;
    }
    /*reset*/
    if (this.e != null) {
        this.e.innerText = this.src_txt;
        this.e.scrollLeft = 0;
        this.e = null;
    }
};

markscript("TextMarquee");
//end TextMarquee.js